package com.hr.controller;

import java.io.IOException;
import java.util.List;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.hr.model.UserModel;
import com.hr.service.KaoqinService;
import com.hr.util.PropertyUtils;

/**
 * 考勤管理
 * 
 * @author fazhen.zheng
 * 
 */
@Controller
public class KaoqinController {
	@Autowired
	private KaoqinService kaoqinService;

	@RequestMapping("/kaoqin/kaoqinList")
	public ModelAndView kaoqinList() {
		ModelAndView mv = new ModelAndView("kaoqin/kaoqinList");
		List wageList = kaoqinService.findAll();
		mv.addObject("kaoqins", wageList);
		mv.addObject("shangban", PropertyUtils.get("shangban"));
		mv.addObject("xiaban", PropertyUtils.get("xiaban"));
		mv.addObject("config", true);
		return mv;
	}
	@RequestMapping("/kaoqin/userList")
	public ModelAndView userList(HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		UserModel user = (UserModel) session.getAttribute("user");
		ModelAndView mv = new ModelAndView("kaoqin/kaoqinList");
		List wageList = kaoqinService.findAll(user.getUser_id());
		mv.addObject("kaoqins", wageList);
		mv.addObject("kaoqin", true);
		mv.addObject("shangban", PropertyUtils.get("shangban"));
		mv.addObject("xiaban", PropertyUtils.get("xiaban"));
		return mv;
	}

	@RequestMapping("/kaoqin/kaoqin")
	public void kaoqin(String type,HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();
		UserModel user = (UserModel) session.getAttribute("user");
		boolean result = kaoqinService.kaoqin(type, user.getUser_id());
		response.getWriter().print(result);
	}
	@RequestMapping("/kaoqin/kaoqinConfig")
	public ModelAndView preapreConfig() {
		ModelAndView mv = new ModelAndView("kaoqin/kaoqinConfig");
		mv.addObject("shangban", PropertyUtils.get("shangban"));
		mv.addObject("xiaban", PropertyUtils.get("xiaban"));
		return mv;
	}
	@RequestMapping("/kaoqin/config")
	public ModelAndView config(String shangban,String xiaban) {
		if(shangban!=null&&xiaban!=null){
			PropertyUtils.set("shangban", shangban);
			PropertyUtils.set("xiaban", xiaban);
		}
		return kaoqinList();
	}

}
